home *** CD-ROM | disk | FTP | other *** search
- #include "menus.h"
- #include "program globals.h"
- #include "key layer.h"
- #include "help.h"
- #include "environment.h"
- #if USE_SOUNDS
- #include "sound layer.h"
- #endif
- #if USE_MUSIC
- #include "music layer.h"
- #endif
- #if USE_PRINTING
- #include "printing layer.h"
- #endif
- #include "program init.h"
- #include "resource layer.h"
- #include "graphics dispatch.h"
- #include "memory layer.h"
- #include "window layer.h"
- #if USE_WINDOWS_MENU
- #include "windows menu.h"
- #endif
- #if USE_SAVE
- #include "save dialog.h"
- #include "pent load-save.h"
- #endif
- #include "pent.h"
- #include "pent main window.h"
- #include "pent editor window.h"
- #include "pent editor files.h"
- #include "pent editor lists.h"
- #include "pent editor dispatch.h"
- #include "pent editor dialogs.h"
- #include "pent meat.h"
- #include "pent floating window.h"
- #include "pent globals.h"
-
- static MenuHandle gAppleMenu=0L;
- static MenuHandle gFileMenu=0L;
- static MenuHandle gEditMenu=0L;
- static MenuHandle gBoardMenu=0L;
- static MenuHandle gOptionsMenu=0L;
- static MenuHandle gEditorMenu=0L;
- #if USE_WINDOWS_MENU
- MenuHandle gWindowsMenu=0L;
- #endif
-
- enum
- {
- mApple = 400, mFile, mEdit, mBoard, mOptions, mEditor,
- #if USE_WINDOWS_MENU
- mWindows,
- #endif
-
- iAbout = 1, iOtherProducts, iHelp,
-
- iNew = 1, iOpen, file_unused1, iClose, iSave, iSaveAs, file_unused2, iPageSetup, iPrint,
- file_unused3, iQuit,
-
- iUndo = 1, edit_unused1, iCut, iCopy, iPaste, iClear, edit_unused2, iSelectAll,
-
- iPlace = 1, iRemove, options_unused1, iSound, iMusic, iMessages, iEffects, iAskBeforeClosing,
- options_unused2, iShowFloat, iAnchorFloat, options_unused3, iAutoSize, iPieceSize,
-
- iOpenEditor = 1, editor_unused1, iNewGroup, iNewBoard, iEditGroup, iDeleteGroup,
- editor_unused2, iClearBoard, iLockBoard, iSaveBoard, editor_unused3, iMessageBox,
- iToolbar,
-
- #if USE_WINDOWS_MENU
- iZoom = 1, iSendToBack
- #else
- enumDummy
- #endif
- };
-
- /*-----------------------------------------------------------------------------------*/
- /* internal stuff for menus.c */
-
- static void HandleAppleMenu(short menuItem);
- static void HandleFileMenu(short menuItem);
- static void HandleEditMenu(short menuItem, Boolean alreadyPassedThrough);
- static void HandleOptionsMenu(short menuItem);
- static void HandleEditorMenu(short menuItem);
- #if USE_WINDOWS_MENU
- static void HandleWindowsMenu(short menuItem);
- #endif
- static void HandleSubMenu(short menuID, short menuItem);
- static void EDItem(MenuHandle theMenu, short theItem, Boolean theCondition);
-
- Boolean InitTheMenus(void)
- {
- Handle MBARHandle;
-
- if ((MBARHandle=GetNewMBar(400))==0L) /* sez which menus are in menu bar. */
- return FALSE;
- SetMenuBar(MBARHandle); /* set this to be THE menu bar to use. */
-
- if ((gAppleMenu=GetMHandle(mApple))==0L) /* GetNewMBar also got menu handles of */
- return FALSE;
- if ((gFileMenu=GetMHandle(mFile))==0L) /* every menu it includes, so just */
- return FALSE;
- if ((gEditMenu=GetMHandle(mEdit))==0L) /* grab these handles and assign them */
- return FALSE;
- if ((gBoardMenu=GetMHandle(mBoard))==0L)
- return FALSE;
- if ((gOptionsMenu=GetMHandle(mOptions))==0L)
- return FALSE;
- if ((gEditorMenu=GetMHandle(mEditor))==0L)
- return FALSE;
-
- #if USE_WINDOWS_MENU
- if ((gWindowsMenu=GetMHandle(mWindows))==0L)
- return FALSE;
- #endif
-
- InitBoardsFileFS();
- RebuildBoardMenu();
-
- AddResMenu(gAppleMenu, 'DRVR'); /* adds control panels to apple menu */
-
- AdjustMenus(); /* dim/enable/check/mark menus/items */
- DrawMenuBar(); /* draws the actual menu bar */
-
- return TRUE;
- }
-
- void ShutDownTheMenus(void)
- {
- gAppleMenu=SafeDisposeMenu(gAppleMenu);
- gFileMenu=SafeDisposeMenu(gFileMenu);
- gEditMenu=SafeDisposeMenu(gEditMenu);
- gBoardMenu=SafeDisposeMenu(gBoardMenu);
- gOptionsMenu=SafeDisposeMenu(gOptionsMenu);
- gEditorMenu=SafeDisposeMenu(gEditorMenu);
- }
-
- void AdjustMenus(void)
- {
- short kind, i;
- WindowRef front, frontDoc, mainWindow, editorWindow;
- Boolean editorIsFront, groupListActive, boardListActive, groupHighlighted;
- Boolean boardHighlighted, boardLocked;
- #if USE_WINDOWS_MENU
- short numOpenWindows;
- #endif
-
- front=FrontWindow();
- kind=front ? ((WindowPeek)front)->windowKind : 0;
- frontDoc=GetFrontDocumentWindow();
- mainWindow=GetIndWindowRef(kMainWindow);
- editorWindow=GetIndWindowRef(kEditorWindow);
- editorIsFront=(frontDoc!=0L) && (frontDoc==editorWindow);
- groupListActive=(editorWindow!=0L) && GroupListActiveQQ();
- boardListActive=(editorWindow!=0L) && BoardListActiveQQ();
- groupHighlighted=(editorWindow!=0L) && (GetHighlightedGroup()>=0);
- boardHighlighted=(editorWindow!=0L) && (GetHighlightedBoard()>=0);
- boardLocked=(editorWindow!=0L) && HighlightedBoardLockedQQ();
- #if USE_WINDOWS_MENU
- numOpenWindows=GetNumberOfOpenWindows();
- #endif
-
- EDItem(gAppleMenu, 0, TRUE);
- EDItem(gAppleMenu, iAbout, TRUE);
- EDItem(gAppleMenu, iOtherProducts, TRUE);
- EDItem(gAppleMenu, iHelp, TRUE);
-
- EDItem(gFileMenu, 0, TRUE);
- EDItem(gFileMenu, iNew, (gCurrentBoardIndex>-1) && ((mainWindow==0L) ||
- (!WindowIsModifiedQQ(mainWindow)) || (!gAskBeforeClosing)));
- EDItem(gFileMenu, iClose, front!=0L);
- #if USE_SAVE
- EDItem(gFileMenu, iOpen, (mainWindow==0L) ||
- (!WindowIsModifiedQQ(mainWindow)) || (!gAskBeforeClosing));
- EDItem(gFileMenu, iSave, (mainWindow!=0L) && (WindowHasLayer(mainWindow)) &&
- (WindowIsModifiedQQ(mainWindow)));
- EDItem(gFileMenu, iSaveAs, mainWindow!=0L);
- #endif
- #if USE_PRINTING
- EDItem(gFileMenu, iPageSetup, TRUE);
- EDItem(gFileMenu, iPrint, (frontDoc!=0L) && (WindowHasLayer(frontDoc)) &&
- (WindowIsPrintableQQ(frontDoc)));
- #endif
- EDItem(gFileMenu, iQuit, TRUE);
-
- EDItem(gEditMenu, 0, TRUE);
- EDItem(gEditMenu, iUndo, (kind<0) || ((mainWindow!=0L) && (frontDoc==mainWindow) && ((gNumPlayed>0) || (gNumHilited>0))));
- EDItem(gEditMenu, iCut, kind<0);
- EDItem(gEditMenu, iCopy, kind<0);
- EDItem(gEditMenu, iPaste, kind<0);
- EDItem(gEditMenu, iClear, kind<0);
- EDItem(gEditMenu, iSelectAll, kind<0);
-
- EDItem(gBoardMenu, 0, TRUE);
-
- EDItem(gOptionsMenu, 0, TRUE);
- EDItem(gOptionsMenu, iPlace, (mainWindow!=0L) && (frontDoc==mainWindow) && (gNumHilited==5) && (gSelectedPieceColor==kSelectedTile));
- EDItem(gOptionsMenu, iRemove, (mainWindow!=0L) && (frontDoc==mainWindow) && (gSelectedPieceColor!=kSelectedTile));
- EDItem(gOptionsMenu, iSound, gSoundAvailable);
- EDItem(gOptionsMenu, iMusic, gMusicAvailable);
- CheckItem(gOptionsMenu, iSound, gSoundToggle&&gSoundAvailable);
- CheckItem(gOptionsMenu, iMusic, gMusicToggle&&gMusicAvailable);
- CheckItem(gOptionsMenu, iMessages, gDisplayMessages);
- CheckItem(gOptionsMenu, iEffects, gGraphicEffects);
- CheckItem(gOptionsMenu, iAskBeforeClosing, gAskBeforeClosing);
- CheckItem(gOptionsMenu, iShowFloat, gShowFloat);
- CheckItem(gOptionsMenu, iAnchorFloat, gAnchorFloat);
- CheckItem(gOptionsMenu, iAutoSize, gAutoSize);
-
- for (i=1; i<=CountMItems(gBoardMenu); i++)
- EDItem(gBoardMenu, i, mainWindow==0L);
- SetBoardCheckmark();
-
- SetItem(gEditorMenu, iOpenEditor, (editorWindow==0L) ? "\pOpen board editor" : "\pBring board editor to front");
- SetItem(gEditorMenu, iEditGroup, groupListActive ? "\pEdit group name" :
- "\pEdit board name and dimensions");
- SetItem(gEditorMenu, iDeleteGroup, groupListActive ? "\pDelete group" : "\pDelete board");
- SetItem(gEditorMenu, iLockBoard, boardLocked ? "\pUnlock board" : "\pLock board");
- SetItem(gEditorMenu, iMessageBox, gShowMessageBox ? "\pHide message box" : "\pShow message box");
- SetItem(gEditorMenu, iToolbar, gShowToolbar ? "\pHide toolbar" : "\pShow toolbar");
- EDItem(gEditorMenu, 0, TRUE);
- EDItem(gEditorMenu, iOpenEditor, !editorIsFront);
- EDItem(gEditorMenu, iNewGroup, editorIsFront);
- EDItem(gEditorMenu, iNewBoard, editorIsFront);
- EDItem(gEditorMenu, iEditGroup, editorIsFront && ((groupListActive && groupHighlighted) ||
- (boardListActive && boardHighlighted && !boardLocked)));
- EDItem(gEditorMenu, iDeleteGroup, editorIsFront && ((groupListActive && groupHighlighted) ||
- (boardListActive && boardHighlighted && !boardLocked)));
- EDItem(gEditorMenu, iClearBoard, editorIsFront && boardHighlighted && !boardLocked);
- EDItem(gEditorMenu, iLockBoard, editorIsFront && boardHighlighted);
- EDItem(gEditorMenu, iSaveBoard, editorIsFront && WindowIsModifiedQQ(editorWindow));
- EDItem(gEditorMenu, iMessageBox, editorIsFront && gShowToolbar);
- EDItem(gEditorMenu, iToolbar, editorIsFront);
-
- #if USE_WINDOWS_MENU
- EDItem(gWindowsMenu, 0, !gInProgress);
- /* EDItem(gWindowsMenu, iArrange, numOpenWindows>0); */
- EDItem(gWindowsMenu, iZoom, (frontDoc!=0L) && (WindowIsZoomableQQ(frontDoc)));
- EDItem(gWindowsMenu, iSendToBack, numOpenWindows>1);
- AdjustWindowsMenu(frontDoc);
- #endif
- }
-
- void HandleMenu(long mSelect)
- {
- short menuID = HiWord(mSelect);
- short menuItem = LoWord(mSelect);
-
- switch (menuID)
- {
- case mApple:
- HandleAppleMenu(menuItem);
- break;
- case mFile:
- HandleFileMenu(menuItem);
- break;
- case mEdit:
- HandleEditMenu(menuItem, FALSE);
- break;
- case mOptions:
- HandleOptionsMenu(menuItem);
- break;
- case mEditor:
- HandleEditorMenu(menuItem);
- break;
- #if USE_WINDOWS_MENU
- case mWindows:
- HandleWindowsMenu(menuItem);
- break;
- #endif
- default:
- if ((menuID>0) && (menuID<=255))
- HandleSubMenu(menuID, menuItem);
- break;
- }
- }
-
- void DoTheCloseThing(WindowPeek theWindow)
- /* a standard close procedure, called when "close" is chosen from File menu or when
- a window is closed through its close box */
- {
- short kind;
-
- if (theWindow==0L)
- return;
-
- kind = theWindow ? theWindow->windowKind : 0;
- if (kind<0) /* DA window or other system window */
- CloseDeskAcc(kind);
- else
- {
- if (WindowHasLayer((WindowRef)theWindow))
- {
- if (OptionKeyWasDown())
- {
- while ((theWindow=(WindowPeek)GetFrontDocumentWindow())!=0L)
- CloseTheWindow((WindowRef)theWindow);
- }
- else
- {
- CloseTheWindow((WindowRef)theWindow);
- }
- }
- else
- {
- DisposeWindow((WindowRef)theWindow);
- }
-
- AdjustMenus();
- }
- }
-
- static void HandleAppleMenu(short menuItem)
- {
- GrafPtr savePort;
- Str255 name;
-
- switch (menuItem)
- {
- case iAbout:
- if (!IndWindowExistsQQ(kAboutWindow))
- OpenTheIndWindow(kAboutWindow, kOpenOldIfPossible);
- else
- MySelectWindow(GetIndWindowRef(kAboutWindow));
- break;
- case iOtherProducts:
- if (!IndWindowExistsQQ(kOtherProductsWindow))
- OpenTheIndWindow(kOtherProductsWindow, kOpenOldIfPossible);
- else
- MySelectWindow(GetIndWindowRef(kOtherProductsWindow));
- break;
- case iHelp:
- if (!IndWindowExistsQQ(kHelpWindow))
- OpenTheIndWindow(kHelpWindow, kOpenOldIfPossible);
- else
- MySelectWindow(GetIndWindowRef(kHelpWindow));
- break;
- default:
- if (menuItem > iHelp+1)
- {
- GetPort(&savePort);
- GetItem(gAppleMenu, menuItem, name);
- OpenDeskAcc(name);
- SetPort(savePort);
- }
- break;
- }
- }
-
- static void HandleFileMenu(short menuItem)
- {
- WindowRef theWindow;
- FSSpec fs;
- TEHandle hTE;
-
- switch (menuItem)
- {
- case iNew:
- NewGame();
- break;
- case iOpen:
- theWindow=GetIndWindowRef(kMainWindow);
- fs=GetWindowFS(theWindow);
- LoadSaveDispatch(&fs, TRUE, FALSE);
- break;
- case iClose:
- if ((theWindow=GetFrontDocumentWindow())!=0L)
- DoTheCloseThing((WindowPeek)theWindow);
- else
- DoTheCloseThing((WindowPeek)FrontWindow());
- break;
- case iSave:
- theWindow=GetIndWindowRef(kMainWindow);
- fs=GetWindowFS(theWindow);
- LoadSaveDispatch(&fs, FALSE, TRUE);
- break;
- case iSaveAs:
- theWindow=GetIndWindowRef(kMainWindow);
- fs=GetWindowFS(theWindow);
- LoadSaveDispatch(&fs, FALSE, FALSE);
- break;
- #if USE_PRINTING
- case iPageSetup:
- DeactivateFloatersAndFirstDocumentWindow();
- DoThePageSetup();
- ActivateFloatersAndFirstDocumentWindow();
- break;
- case iPrint:
- theWindow=GetFrontDocumentWindow();
- if ((WindowHasLayer(theWindow)) && (WindowIsPrintableQQ(theWindow)))
- {
- hTE=GetWindowTE(theWindow);
- if (hTE!=0L)
- {
- DeactivateFloatersAndFirstDocumentWindow();
- PrintText(hTE);
- ActivateFloatersAndFirstDocumentWindow();
- }
- }
- else SysBeep(7);
- break;
- #endif
- case iQuit:
- gDone=ShutDownTheProgram();
- break;
- }
- }
-
- static void HandleEditMenu(short menuItem, Boolean alreadyPassedThrough)
- {
- WindowRef theWindow;
- DispatchError resultCode;
-
- if (!alreadyPassedThrough)
- theWindow=FrontWindow();
- else
- {
- theWindow=GetFrontDocumentWindow();
- }
-
- if (theWindow!=0L)
- {
- switch (menuItem)
- {
- case iUndo: resultCode=UndoDispatch(theWindow); break;
- case iCut: resultCode=CutDispatch(theWindow); break;
- case iCopy: resultCode=CopyDispatch(theWindow); break;
- case iPaste: resultCode=PasteDispatch(theWindow); break;
- case iClear: resultCode=ClearDispatch(theWindow); break;
- case iSelectAll: resultCode=SelectAllDispatch(theWindow); break;
- default: resultCode=kSuccess; break;
- }
-
- if ((resultCode==kPassThrough) && (!alreadyPassedThrough))
- HandleEditMenu(menuItem, TRUE);
- }
- else SystemEdit(menuItem-1);
- }
-
- static void HandleOptionsMenu(short menuItem)
- {
- switch (menuItem)
- {
- case iPlace:
- PlaceUnknownPiece(GetIndWindowRef(kMainWindow));
- break;
- case iRemove:
- RemovePiece(GetIndWindowRef(kMainWindow));
- break;
- case iSound:
- gSoundToggle=!gSoundToggle;
- DoSound(sound_on, TRUE);
- break;
- case iMusic:
- gMusicToggle=!gMusicToggle;
- if (gMusicToggle)
- StartTheMusic();
- else
- CloseTheMusicChannel();
- break;
- case iMessages:
- gDisplayMessages=!gDisplayMessages;
- break;
- case iEffects:
- gGraphicEffects=!gGraphicEffects;
- break;
- case iAskBeforeClosing:
- gAskBeforeClosing=!gAskBeforeClosing;
- break;
- case iShowFloat:
- ToggleShowFloatingWindow();
- break;
- case iAnchorFloat:
- ToggleAnchorFloatingWindow();
- break;
- case iAutoSize:
- gAutoSize=!gAutoSize;
- break;
- case iPieceSize:
- DoPieceSizeDialog();
- DealWithChangedPieceSize(GetIndWindowRef(kMainWindow));
- break;
- }
- }
-
- static void HandleEditorMenu(short menuItem)
- {
- WindowRef theWindow;
-
- theWindow=GetIndWindowRef(kEditorWindow);
- if (menuItem==iOpenEditor)
- {
- if (theWindow==0L)
- OpenTheIndWindow(kEditorWindow, kAlwaysOpenNew);
- else
- MySelectWindow(theWindow);
- return;
- }
- else if (theWindow==0L)
- return;
-
- RememberEditorButtonState(theWindow);
-
- switch (menuItem)
- {
- case iNewGroup:
- DoNewDispatch(theWindow, TRUE);
- break;
- case iNewBoard:
- DoNewDispatch(theWindow